package com.ccf.business.etl.controller;

import java.util.Arrays;
import java.util.stream.Collectors;

import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.common.model.pojo.Query;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import com.ccf.business.etl.model.FlowLog;
import com.ccf.business.etl.service.IFlowLogService;
import com.common.model.result.PageResult;
import com.common.model.result.Result;

/**
 * 流程日志
 *
 * @author ccf
 * @date 2021-12-07 18:19:02
 */
@Slf4j
@RestController
@RequestMapping("/flowlog")
@Api(tags = "流程日志")
public class FlowLogController {
    @Autowired
    private IFlowLogService flowLogService;

    /**
     * 列表
     */
    @ApiOperation(value = "分页查询列表")
    @GetMapping
    public PageResult list(Query query) {
        return flowLogService.findList(query);
    }


    /**
     * 查询
     */
    @ApiOperation(value = "查询")
    @GetMapping("/{id}")
    public Result getById(@PathVariable String id) {
        FlowLog model = flowLogService.getById(id);
        return Result.succeed(model, "查询成功");
    }

    /**
     * 新增or更新
     */
    @ApiOperation(value = "保存")
    @PostMapping
    public Result save(@RequestBody FlowLog flowLog) {
        flowLogService.saveOrUpdate(flowLog);
        return Result.succeed("保存成功");
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id) {
        //批量删除
        if (StrUtil.contains(id, ",")){
            String[] ids = StrUtil.split(id, ",");
            flowLogService.removeByIds(Arrays.stream(ids).collect(Collectors.toList()));
        } else {
            flowLogService.removeById(id);
        }
        return Result.succeed("删除成功");
    }
}
